<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="com.bms.util.PageUtil"%>
<%@page import="com.bms.entity.Author"%>
<%@page import="java.util.List"%>
<%@page import="com.bms.dao.AuthorDao"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>图书管理信息系统-作者管理</title>
<link rel=stylesheet href="../inc/main.css" type="text/css">
<style type="text/css">
</style>
</head>
<body>
	<%@include file="/inc/head.jsp"%>
	<table align="center" width="980">
		<tr>
			<td align="right">
				<a href="#" onclick="window.open('<%=request.getContextPath() %>/authors/add.jsp', '', 'width=280,height=130')">添加作者</a>
			</td>
		</tr>
	</table>
	<table align="center" width="980">
		<caption>作者列表</caption>
		<tr>
			<th width="150">作者ID</th>
			<th width="300">名</th>
			<th width="300">姓</th>
			<th width="230">操作</th>
		</tr>
		<%
			int pageSize=3;
			
			int currentPage=1;
			//获取当前的页
			String pageParam=request.getParameter("page");
			if(StringUtils.isNotBlank(pageParam)){
				currentPage=Integer.parseInt(pageParam);
			}
		
			AuthorDao dao=new AuthorDao();
			List<Author> authors=dao.queryAll();
			
			PageUtil pageUtil=new PageUtil(pageSize,currentPage,authors.size());
			
			if(authors!=null&&authors.size()>0){
				for(int i=pageUtil.beginIndex();i<pageUtil.endIndex();i++){	
					Author author=authors.get(i);
		%>
		<tr>
			<td>
				<%=(i+1) %>
			</td>
			<td>
				<%=author.getLastName()%>
			</td>
			<td>
				<%=author.getFirstName() %>
			</td>
			<td align="center">
				<a href="<%=request.getContextPath()%>/authorAction?method=delete&id=<%=author.getId()%>">删除 </a> 
				<a href="#" onclick="window.open('<%=request.getContextPath() %>/authors/edit.jsp?id=<%=author.getId()%>', '', 'width=280,height=130')">修改</a>
			</td>
		</tr>
		<%
				}
			}else{
		%>
		<tr>
			<td colspan="4" align="center">
				没有任何的作者信息！
			</td>
		</tr>
		<%
			}
		%>
		<tr>
			<td colspan="4" align="right">
				记录总数 <%=authors.size() %> 条 每页显示 <%=pageSize %> 条 
				当前页/总页数 <%=currentPage %>/<%=pageUtil.getTotalPage() %> 
				<a href="<%=request.getContextPath() %>/authors/index.jsp?page=1">首页</a> 
				<a href="<%=request.getContextPath() %>/authors/index.jsp?page=<%=pageUtil.prePage()%>">上页</a> 
				<a href="<%=request.getContextPath() %>/authors/index.jsp?page=<%=pageUtil.nextPage()%>">下页 </a>
				<a href="<%=request.getContextPath() %>/authors/index.jsp?page=<%=pageUtil.nextPage()%>">末页 </a>
			</td>
		</tr>
	</table>
</html>